package backend;


import com.vmware.vim25.*;
import java.net.*;




public class Connection {
	
	private ManagedObjectReference _svcRef;
	private VimServiceLocator locator;
	private VimPortType _service;
	private ServiceContent _sic;
	
	private Connection(){};
	
	public Connection(String hostName, String userName, String password)
	throws Exception{
		System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
		String url = "https://"+hostName+"/sdk/vimService"; //hier muss die URL des ESXI Servers angegebenwerden
		
		createServiceRef();
		locator = new VimServiceLocator();
		//setMaintainSession?????????
		URL test = new URL(url);
		_service = locator.getVimPort(test);
		_sic = _service.retrieveServiceContent(_svcRef);
		if (_sic.getSessionManager() != null) {
			_service.login(_sic.getSessionManager(), userName, password, null);
		}
		System.out.println(_sic.getAbout().getFullName());
		System.out.println("API type is " + _sic.getAbout().getApiType()); 
		System.out.println("API version is " + _sic.getAbout().getApiVersion()); 
	}
	
	private void createServiceRef() throws Exception{
		_svcRef = new ManagedObjectReference();
		_svcRef.setType("ServiceInstance");
		_svcRef.set_value("ServiceInstance");
	}
	

}
